package com.tong.hao.common.configuration.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @ClassName AcServletContextListener
 * @Author 友野浩二
 * @Description ServletContext监听器
 * @Version 1.0
 */
@WebListener
@Slf4j
public class HaoServletContextListener implements ServletContextListener, ServletContextAttributeListener {

    @Override
    public void contextInitialized(ServletContextEvent sce) {
//        ServletContext servletContext = sce.getServletContext();
//        WebApplicationContext webApplicationContext = (WebApplicationContext) servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
//        webApplicationContext.getBean("tongServiceImpl");
        log.info("Hao Common ServletContext initialized");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        log.info("Hao Common ServletContext destroyed");
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent scae) {
        log.info("Hao Common ServletContext attribute added");
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent scae) {
        log.info("Hao Common ServletContext attribute removed");
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent scae) {
        log.info("Hao Common ServletContext attribute replaced");
    }
}
